﻿//字符处理小软件

using System;
using System.Windows.Forms;

namespace Nathan_tools
{
    public partial class frm_autowordwrap : Form
    {
        public frm_autowordwrap()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int linelength= Convert.ToInt16(tb_line_length.Text);
            string [] p=tb_towordwrap .Text.Replace ("\r","") .Split ('\n');   //进行分段

            string temp="";

            foreach (string p1 in p)                           //对每段进行处理
            {
                int lines=p1.Length / linelength;              //一段文本可以分成的行数

                for (int line = 0; line < lines; line++)
                {
                    temp += p1.Substring(line * linelength, linelength) + "\r\n";
                }

                if( p1.Length % linelength>0)                  //处理最后一行剩余的字符
                    temp += p1.Substring(lines * linelength, p1.Length % linelength) + "\r\n";
            }

            tb_towordwrap.Clear();
            tb_towordwrap.Text += temp;

                    
        }

        private void tb_towordwrap_TextChanged(object sender, EventArgs e)
        {
            lb_char_count.Text = tb_towordwrap.Text.Length.ToString ();
        }

        private void btn_autowordwrap_Click(object sender, EventArgs e)
        {
            if (tb_towordwrap.WordWrap == true  )
            {
                btn_autowordwrap.Text = "自动分段显示";
                tb_towordwrap.WordWrap =false ;
            }
            else
            {
               btn_autowordwrap.Text = "取消自动分段显示";
               tb_towordwrap.WordWrap = true ;       
            }
        }

        private void tb_towordwrap_MouseUp(object sender, MouseEventArgs e)
        {
            lb_selectedchars.Text = tb_towordwrap.SelectionLength.ToString();
        }

        private void frm_autowordwrap_Load(object sender, EventArgs e)
        {

        }

    }
}

//下载地址：http://u.115.com/file/f1f6b3352f# killprocess.rar Designed by Nathan Zhang QQ:5521833